﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using DuSQL.API;

namespace DuSQL.UI
{
    /// <summary>
    /// ShowData.xaml 的交互逻辑
    /// </summary>
    public partial class ShowData : Page
    {
        private string connstr = "";
        private NodeType dbtype;
        private string tablename = "";
        public ShowData(string title, string connstring, NodeType databasetype, string tbname)
        {
            InitializeComponent();
            connstr = connstring;
            dbtype = databasetype;
            this.Title = title;
            tablename = tbname;
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            string sql = "select * from [" + tablename + "]"; 
            DuSQL.API.DbHelper.webstr = connstr;
            switch (dbtype)
            {
                case NodeType.DbConnection_Access:
                    {
                        DataTable dt = DuSQL.API.DbHelper.Query(sql).Tables[0];
                        gvData.ItemsSource = dt.DefaultView;
                        break;
                    }
                case NodeType.DbConnection_SqlServer:
                    {
                        DataTable dt = DuSQL.API.DbHelperSQL.Query(connstr, sql).Tables[0];
                        gvData.ItemsSource = dt.DefaultView;
                        break;
                    }
            }


        }
    }
}
